//
//  MediaImproveController.m
//  Nurse
//
//  Created by RainSets on 8/29/14.
//  Copyright (c) 2014 Honeywell. All rights reserved.
//

#import "MediaImproveController.h"
#import "PatientService.h"
#import "AddMediaViewController.h"
#import "MediaCell.h"
#import <TPKeyboardAvoidingTableView.h>
#import <QuartzCore/QuartzCore.h>
#import "PatientInfoView.h"

@interface MediaImproveController ()
@property (nonatomic, strong) PatientInfoView *pInfoView;
@property (weak, nonatomic) IBOutlet TPKeyboardAvoidingTableView *tableVMediaContent;
@property (nonatomic, strong) NSArray *arrListData;

- (IBAction)backAction:(id)sender;
- (IBAction)doneAction:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *btnDoneBottom;
@property (weak, nonatomic) IBOutlet UILabel *lblTitle;
- (IBAction)cancelActionTop:(id)sender;

@end

@implementation MediaImproveController
@synthesize pInfoView = _pInfoView;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
    
    _arrListData = @[@"标题",@"事件",@"科室",@"请确认病人信息"];
    
    NSArray *ibs = [[NSBundle mainBundle] loadNibNamed:@"PatientInfoView" owner:nil options:nil];
    // TestView *test = [ibs objectAtIndex:0];2
    _pInfoView = (PatientInfoView *)[ibs objectAtIndex:0];
    [_pInfoView setFrame:CGRectMake(0.f, 64.f, _pInfoView.frame.size.width, _pInfoView.frame.size.height)];
    _pInfoView.backgroundColor=[UIColor colorWithRed:154/255.0 green:238/255.0 blue:225/255.0 alpha:1];
    [self.view addSubview:_pInfoView];
    
    NSDictionary* patient = [[PatientService sharedInstance]currentPatient];
    _pInfoView.txtPatientName.text = [patient valueForKey:@"姓名"];
    _pInfoView.txtPatientID.text = [NSString stringWithFormat:@"住院号:%@",[patient valueForKey:@"住院号"]];
    _pInfoView.txtBedNo.text = [NSString stringWithFormat:@"床位号:%@",[patient valueForKey:@"床位号"]];
    NSString*xb= [patient valueForKey:@"性别"];
    if ([xb isEqualToString:@"女"]) {
        _pInfoView.imgxb.image=[UIImage imageNamed:@"gender-female2.png"];
    }
    else{
        _pInfoView.imgxb.image=[UIImage imageNamed:@"gender-male2.png"];
    }
    
    [self setrightBarButtonItem:@""orImaged:@"head-icon_03.png" Event:@selector(rightBar_clicked:)];
    
    [[_btnDoneBottom layer] setCornerRadius:3.f];
    [_tableVMediaContent setDataSource:(id<UITableViewDataSource>)self];
    [_tableVMediaContent setDelegate:(id<UITableViewDelegate>)self];
    
    
    
    
}

-(void)setBtnDetailImg:(UIImage *)detailImg{
    [_lblTitle setText:@"添加图片"];
    UIView *headerV = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, CGRectGetWidth(self.view.bounds), 125.f)];
    [headerV setBackgroundColor:[UIColor clearColor]];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setFrame:CGRectMake(0.f, 0.f, 121.f, 121.f)];
    [[btn layer] setCornerRadius:3.f];
    [btn setCenter:headerV.center];
    [btn setImage:detailImg forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(showImgAction:) forControlEvents:UIControlEventTouchUpInside];
    [headerV addSubview:btn];
    [_tableVMediaContent setTableHeaderView:headerV];
    headerV = nil;
}

-(void)setBtnDetailVideo:(NSURL *)videoUrl{
    [_lblTitle setText:@"添加视频"];
    
    UIView *headerV = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, CGRectGetWidth(self.view.bounds), 125.f)];
    [headerV setBackgroundColor:[UIColor clearColor]];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setFrame:CGRectMake(0.f, 0.f, 121.f, 121.f)];
    [[btn layer] setCornerRadius:3.f];
    [btn setCenter:headerV.center];
    [btn setImage:[UIImage imageNamed:@"MediaVideo.png"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(showImgAction:) forControlEvents:UIControlEventTouchUpInside];
    [headerV addSubview:btn];
    [_tableVMediaContent setTableHeaderView:headerV];
    headerV = nil;
}

-(void)setBtnDetailAudio:(NSURL *)audioUrl{
    [_lblTitle setText:@"添加音频"];
    UIView *headerV = [[UIView alloc] initWithFrame:CGRectMake(0.f, 0.f, CGRectGetWidth(self.view.bounds), 125.f)];
    [headerV setBackgroundColor:[UIColor clearColor]];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setFrame:CGRectMake(0.f, 0.f, 121.f, 121.f)];
    [[btn layer] setCornerRadius:3.f];
    [btn setCenter:headerV.center];
    [btn setImage:[UIImage imageNamed:@"MediaVoice.png"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(showVideoAction:) forControlEvents:UIControlEventTouchUpInside];
    [headerV addSubview:btn];
    [_tableVMediaContent setTableHeaderView:headerV];
    headerV = nil;
}

-(void)rightBar_clicked:(id)sender{
    AddMediaViewController *addMediaVC = [[AddMediaViewController alloc] initWithNibName:@"AddMediaViewController" bundle:nil];
    [self.navigationController pushViewController:addMediaVC animated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44.f;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_arrListData count];
}


- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
	return UITableViewCellEditingStyleNone;
}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    [cell.textLabel setText:_arrListData[indexPath.row]];
    //config the cell
    return cell;
}

- (void)showImgAction:(id)sender {
    
}

- (void)showVideoAction:(id)sender {
    
}

- (IBAction)backAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)doneAction:(id)sender {
    
}
- (IBAction)cancelActionTop:(id)sender {
}
@end
